﻿using System;
using System.Collections.Generic;
using System.Globalization;
using Bule.Malbilden.Domain;
using System.Xml.Linq;

namespace Bule.Malbilden.Configuration
{
    public class XmlNutritionGoalConfigurationReader : INutritionGoalConfigurationReader
    {
        IConfigurationReader reader;

        public XmlNutritionGoalConfigurationReader()
        {
            reader = new XmlConfigurationReader("Xml/DefaultGoal.xml");
        }

        public XmlNutritionGoalConfigurationReader(IConfigurationReader reader)
        {
            this.reader = reader;
        }

        public DayNutritionGoal GetDefaultGoal()
        {
            IDictionary<string, string> goalDictionary = reader.GetConfigurationDictionary();

            double proteinPercentage = Convert.ToDouble(goalDictionary["protein_percentage"], CultureInfo.InvariantCulture);
            double carbohydratePercentage = Convert.ToDouble(goalDictionary["carbohydrate_percentage"], CultureInfo.InvariantCulture);
            double fatPercentage = Convert.ToDouble(goalDictionary["fat_percentage"], CultureInfo.InvariantCulture);
            double fiberWeight = Convert.ToDouble(goalDictionary["fiber"], CultureInfo.InvariantCulture);

            return new DayNutritionGoal(0, (int)proteinPercentage, (int)carbohydratePercentage, 
                (int)fatPercentage, (int)fiberWeight, new DateTime(1900, 01, 01));
        }
    }
}
